home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Science⁄Math
/
Scientist's Helper src
/
s.helper.3
/
regcmdloop.c
next >
Wrap
C/C++ Source or Header
|
1986-02-06
|
11KB
|
476 lines
#include "all.h"
#include "regtabext.h"
CmdFromWnd(c, fromCommandWindow)
char c[];
int fromCommandWindow;
{
if( c[0]=='>' ) { /* get rid of prompt */
c[0]=' ';
}
RegTabCmd( c, fromCommandWindow );
}
RegTabCmd( c, fromCommandWindow )
char c[];
int fromCommandWIndow;
{
int i, j, k, ii, jj;
float x, y;
char s[cmdWordLen];
strncpy( command.cmdStr, c, cmdWordLen-1 );
command.cmdStr[cmdWordLen-1] = '\0'; /*just in case*/
if( !SBreak(&command, TRUE) ) {
WriteLine("bad command line");
ErrMsg(command.cmdStr);
}
strcpy( cmdWord0, command.cmdWord[0] );
/*special code to handle case of pending input*/
/*several commands ask for input, including the cursor and input commands*/
if( pendingFlag ) {
pendingFlag=FALSE;
NoPendingInput();
if( strlen(pentName)!=0 ) {
if( !SetVar(pentName,cmdWord0) ) {
ErrMsg("couldnt set input variable");
}
}
}
else {
if( (strlen(cmdWord0)==0) || (strcmp(cmdWord0,"label")==0) ) {
; /*do nothing*/
}
else if( strcmp(cmdWord0,"quit")==0 ) {
doneFlag = TRUE;
}
else if( (strcmp(cmdWord0,"p")==0) || (strcmp(cmdWord0,"prompt")==0) ) {
for( i=1; i<(numCmdWds-1); i++ ) {
if(strlen(command.cmdWord[i])!=0) WritePhrase( command.cmdWord[i] );
}
WriteLine( command.cmdWord[numCmdWds-1] );
}
else if ( strcmp(cmdWord0,"beep")==0 ) {
SysBeep(5);
}
else if( strcmp(cmdWord0,"setvar")==0 ) {
if( !SetVar( command.cmdWord[1], command.cmdWord[2] ) ) {
ErrMsg("couldnt create variable");
}
}
else if( strcmp(cmdWord0,"delete")==0 ) {
if( (strcmp(command.cmdWord[1],"v")==0) || (strcmp(command.cmdWord[1],"variable")==0) ){
if( !DelVar( command.cmdWord[2] ) ) {
ErrMsg("couldnt delete variable");
}
}
else {
DelCommand();
RedoEditWindow();
}
}
else if( (strcmp(cmdWord0,"t")==0) || (strcmp(cmdWord0,"type")==0) ) {
if( (strcmp(command.cmdWord[1],"v")==0) || (strcmp(command.cmdWord[1],"variables")==0) ) {
ListVars();
}
else if( (strcmp(command.cmdWord[1],"c")==0) || (strcmp(command.cmdWord[1],"col")==0) ) {
SToI( command.cmdWord[2], &i );
if( GoodCol(i)!=0 ) {
ErrMsg( noSuchColumn );
}
WriteLine( table.header.colName[i-1] );
for( j=1; j<=table.header.rows; j++ ) {
CheckAbortMenu();
GetTable( j, i, &x );
IToS( j, s );
strcat( s, " " );
WritePhrase( s );
RToS( x, s );
WriteLine( s );
}
}
else {
ErrMsg( noSuchModifier );
}
}
else if( strcmp(cmdWord0,"allocate")==0 ) {
SToI( command.cmdWord[1], &i );
SToI( command.cmdWord[2], &j );
AllocTable( i, j );
RedoEditWindow();
}
else if( strcmp(cmdWord0,"title")==0 ) {
strcpy( table.header.title, command.cmdWord[1] );
Header2Vars();
}
else if( strcmp(cmdWord0,"interpolated")==0 ) {
if( (strlen(command.cmdWord[1])==0) || (strcmp(command.cmdWord[1],"true")==0) ) {
table.header.interpolated = TRUE;
}
else if( strcmp(command.cmdWord[1],"false")==0 ) {
table.header.interpolated = FALSE;
}
else {
ErrMsg( noSuchModifier );
}
Header2Vars();
CreateCol1();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"rows")==0 ) {
SToI( command.cmdWord[1], &i );
if( GoodRow(i)==2 ) {
ErrMsg( noSuchRow );
}
else {
j = table.header.rows;
table.header.rows = i;
Header2Vars();
if( j<i ) {
CreateCol1();
}
RedoEditWindow();
}
}
else if( strcmp(cmdWord0,"cols")==0 ) {
SToI( command.cmdWord[1], &i );
if( GoodCol(i)==2 ) {
ErrMsg( noSuchCol );
}
else {
table.header.cols = i;
Header2Vars();
RedoEditWindow();
}
}
else if( strcmp(cmdWord0,"start")==0 ) {
SToR( command.cmdWord[1], &x, FALSE );
table.header.start = x;
Header2Vars();
CreateCol1();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"samp")==0 ) {
SToR( command.cmdWord[1], &x, FALSE );
if( x==0.0 ) {
ErrMsg("samp cant be zero");
}
table.header.samp = x;
Header2Vars();
CreateCol1();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"colname")==0 ) {
SToI( command.cmdWord[1], &i );
if( GoodCol(i)!=0 ) {
ErrMsg( noSuchCol );
}
strcpy( s, command.cmdWord[2] );
s[10] = '\0'; /*just in case its too long*/
strcpy( table.header.colName[i-1], s );
RedoEditWindow();
}
else if( strcmp(cmdWord0,"table")==0 ) {
SToI( command.cmdWord[1], &i );
SToI( command.cmdWord[2], &j );
if( strlen(command.cmdWord[3])==0 ) {
GetTable(i, j, &x);
RToS( x, s );
WriteLine( s );
}
else {
SToR( command.cmdWord[3], &x, TRUE );
SetTable( i, j, x, FALSE );
RedoEditWindow();
}
}
else if( strcmp(cmdWord0,"set")==0 ) {
if( strcmp(command.cmdWord[2],"table")==0 ) {
SToI( command.cmdWord[3], &i );
SToI( command.cmdWord[4], &j );
GetTable(i, j, &x);
RToS( x, s );
if( !SetVar( command.cmdWord[1],s) ) {
ErrMsg("couldnt create variable");
}
}
else if( strcmp(command.cmdWord[2],"colname")==0 ) {
SToI( command.cmdWord[3], &i );
if( GoodCol(i)!=0 ) {
ErrMsg( noSuchColumn );
}
if( !SetVar(command.cmdWord[1],table.header.colName[i-1]) ) {
ErrMsg("couldnt create variable");
}
}
else if( strcmp(command.cmdWord[2],"coefficient")==0 ) {
SToI( command.cmdWord[3], &i );
if( (i<0) || (i>nCoeffs) ) {
ErrMsg( "no such coefficient" );
}
RToS( coeffs[i], s );
if( !SetVar(command.cmdWord[1],s )) {
ErrMsg("couldnt create variable");
}
}
else {
ErrMsg( noSuchModifier );
}
}
else if ( (strcmp(cmdWord0,"x")==0) || (strcmp(cmdWord0,"execute")==0) ) {
if( !mem.active ) { /*calls from console construct new label list*/
ListLabels(); /*calls from within procedure cannot change procedure memory*/
PendingInput();
mem.active = TRUE;
}
if( !FindLabel(command.cmdWord[1],&i) ) {
ErrMsg( "cant find label" );
}
else if( mem.stackPtr >= (stackLen-1) ) {
ErrMsg( "too many levels of procedures" );
}
mem.stackPtr++;
mem.stack[mem.stackPtr] = i;
i = SetVar("arg1",command.cmdWord[2] ) && SetVar("arg2",command.cmdWord[3] )
&& SetVar("arg3",command.cmdWord[4] ) && SetVar("arg4",command.cmdWord[5] );
if (!i) {
ErrMsg("not enough space for argument variables");
}
}
else if( strcmp(cmdWord0,"goto")==0 ) {
if( !mem.active ) {
ErrMsg("cant goto from console");
}
if( !FindLabel(command.cmdWord[1],&i) ) {
ErrMsg( "cant find label" );
}
mem.stack[mem.stackPtr] = i;
}
else if( strcmp(cmdWord0,"return")==0 ) {
ReturnCommand();
}
else if( strcmp(cmdWord0,"for")==0 ) {
ForCommand();
}
else if( strcmp(cmdWord0,"next")==0 ) {
NextCommand();
}
else if( strcmp(cmdWord0,"if")==0 ) {
IfCommand();
}
else if( (strcmp(cmdWord0,"vm")==0) || (strcmp(cmdWord0,"vmath")==0) ) {
VMathCommand();
}
else if( (strcmp(cmdWord0,"vf")==0) || (strcmp(cmdWord0,"vfunction")==0) ) {
VFunctionCommand();
}
else if( strcmp(cmdWord0,"concat")==0 ) {
strcpy(s,command.cmdWord[2]);
for( i=3; i<numCmdWds; i++ ) {
j=cmdWordLen - strlen(s) - 1;
strncat(s,command.cmdWord[i],j);
}
if( !SetVar(command.cmdWord[1],s) ) {
ErrMsg("couldnt create variable");
}
}
else if( strcmp(cmdWord0,"sleep")==0 ) {
SToR( command.cmdWord[1], &x, FALSE );
i = (int)(x*60.0);
Delay( (long)i, (long*)(&x));
}
else if( strcmp(cmdWord0,"input")==0 ) {
WriteLine( command.cmdWord[2] );
strcpy( pentName, command.cmdWord[1] );
pendingFlag=TRUE;
PendingInput();
}
else if( strcmp(cmdWord0,"cursor")==0 ) {
WriteLine( command.cmdWord[1] );
pentName[0]='\0';
pendingFlag=TRUE;
PendingInput();
SelectWindow(theWindow[grWindow]);
}
else if( strcmp(cmdWord0,"xaxis")==0 ) {
SToR( command.cmdWord[1], &x, FALSE);
SToR( command.cmdWord[2], &y, FALSE);
if( x<y ) {
graph.xMin=x;
graph.xMax=y;
}
else {
ErrMsg("xmin > xmax");
}
Graph2Vars();
}
else if( strcmp(cmdWord0,"yaxis")==0 ) {
SToR( command.cmdWord[1], &x, FALSE);
SToR( command.cmdWord[2], &y, FALSE);
if( x<y ) {
graph.yMin=x;
graph.yMax=y;
}
else {
ErrMsg("ymin > ymax");
}
Graph2Vars();
}
else if( strcmp(cmdWord0,"plot")==0 ) {
PlotCol();
}
else if( strcmp(cmdWord0,"clear")==0 ) {
ClearGraph();
}
else if( strcmp(cmdWord0,"axes")==0 ) {
PlotAxes();
}
else if( strcmp(cmdWord0,"insert")==0 ) {
InsCommand();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"trend")==0 ) {
Trend();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"interpolate")==0 ) {
TabInterpolate();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"spline")==0 ) {
SplInterpolate();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"sort")==0 ) {
SortTable();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"polyfit")==0 ) {
polyfit();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"multifit")==0 ) {
multifit();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"noise")==0 ) {
noise();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"mean")==0 ) {
Mean();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"swap")==0 ) {
SwapCommand();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"copy")==0 ) {
CopyCommand();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"scale")==0 ) {
GScan();
Graph2Vars();
}
else if( (strcmp(cmdWord0,"cm")==0) || (strcmp(cmdWord0,"cmath")==0) ) {
ColMath();
RedoEditWindow();
}
else if( (strcmp(cmdWord0,"cf")==0) || (strcmp(cmdWord0,"cfunction")==0) ) {
ColFunction();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"min")==0 ) {
SToI( command.cmdWord[1], &i );
ColMin( i, &x );
RToS( x, s );
WriteLine(s);
if( !SetVar("min",s) ) {
ErrMsg("couldnt set variable");
}
}
else if( strcmp(cmdWord0,"max")==0 ) {
SToI( command.cmdWord[1], &i );
ColMax( i, &x );
RToS( x, s );
WriteLine(s);
if( !SetVar("max",s) ) {
ErrMsg("couldnt set variable");
}
}
else if( strcmp(cmdWord0,"constant")==0 ) {
SToR( command.cmdWord[1], &x, TRUE );
SToI( command.cmdWord[2], &j );
if( strlen(command.cmdWord[3])==0 ) {
ii=1;
}
else {
SToI( command.cmdWord[3], &ii );
}
if( strlen(command.cmdWord[4])==0 ) {
jj=table.header.rows;
}
else {
SToI( command.cmdWord[4], &jj );
}
for( i=ii; i<=jj; i++ ) {
SetTable( i, j, x, FALSE );
}
RedoEditWindow();
}
else if( strcmp(cmdWord0,"bandpass")==0 ) {
bandpass();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"spectrum")==0 ) {
spect();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"integrate")==0 ) {
integrate();
RedoEditWindow();
}
else if( (strcmp(cmdWord0,"diff")==0) || (strcmp(cmdWord0,"differentiate")==0) ) {
differentiate();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"sum")==0 ) {
summation();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"histogram")==0 ) {
histogram();
RedoEditWindow();
}
else if( strcmp(cmdWord0,"taper")==0 ) {
taper();
RedoEditWindow();
}
else if( (strcmp(cmdWord0,"conv")==0) || (strcmp(cmdWord0,"convolve")==0) ) {
convolve();
RedoEditWindow();
}
else {
ErrMsg("no such command");
}
} /*end if not pending*/
if( (!mem.active) && (!pendingFlag) ) { /*prompt to command window*/
currentWindow = coWindow;
whichWindow = theWindow[currentWindow];
SelectWindow( whichWindow );
SetPort(whichWindow);
TEInsert( "> ", 2L, coText );
IfOutScroll( coText );
}
}